/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Welcome;

import javax.microedition.lcdui.Image;

/**
 *
 * @author virtual truong
 */
public class ImageScaled {

    public static Image CreateScaledImage(Image imgOldImage, int iNewWidth, int iNewHeight) {
        Image imgNewImage = null;
        final int iOldWidth = imgOldImage.getWidth();
        final int iOldHeight = imgOldImage.getHeight();
        int iOldRGBArray[] = new int[iOldWidth * iOldHeight];

        imgOldImage.getRGB(iOldRGBArray, 0, iOldWidth, 0, 0, iOldWidth, iOldHeight);

        int iNewRGBArray[] = new int[iNewWidth * iNewHeight];
        for (int yy = 0; yy < iNewHeight; yy++) {
            int dy = yy * iOldHeight / iNewHeight;

            for (int xx = 0; xx < iNewWidth; xx++) {
                int dx = xx * iOldWidth / iNewWidth;

                iNewRGBArray[(iNewWidth * yy) + xx] = iOldRGBArray[(iOldWidth * dy) + dx];
            }
        }
        imgNewImage = Image.createRGBImage(iNewRGBArray, iNewWidth, iNewHeight, true);
        iNewRGBArray=null;
        System.gc();

        return imgNewImage;
    }
}
